package br.com.felix.fwt.ui;

import java.io.PrintWriter;

import br.com.felix.fwt.ui.exception.ComponentRenderException;
import br.com.felix.fwt.ui.javascript.JavascriptListener;


/**
 * The Class Fieldset implements the HTML fieldset component.
 */
public class Fieldset extends Panel {

	private static final long serialVersionUID = 8511941053406286653L;

	{
		this.cssClass = "fwtfieldset";
	}

	
	/* (non-Javadoc)
	 * @see br.com.felix.fwt.ui.Panel#write(java.io.PrintWriter)
	 */
	@Override
	public void write(PrintWriter out) throws ComponentRenderException {
		if(!authorized()) return;
		out.write("\n<div class=\"");
		out.write(cssClass);
		out.write("\" ");
		out.write("id=\""); 
		out.write(getName());
		out.write("\" ");
		if(javascripts != null){
			for(JavascriptListener js: javascripts){
				out.write(js.script());
			}
		}
		if(style!=null){
			out.write(style);
		}
		out.write(">\n<fieldset>\n<legend>\n");
		out.write(getValue());
		out.write("\n</legend>");
		writeChilds(out);
		out.write("\n</fieldset>\n</div>");
	}
}
